<template>
  <div class="storeUserModify common-container">
    <div class="common-top">
      <span class="left">
        <span class="go-back" @click.stop="$router.go(-1)">返回</span>
      </span>
      <el-button type="primary" @click="save">保存</el-button>
    </div>
    <div class="common-bot">
      <div class="modify-bot">
        <el-form :model="form" label-width="100px">
          <el-form-item required label="支付金额" style="width: 30%">
            <el-input v-model="form.money"></el-input>
          </el-form-item>
          <el-form-item required label="实际到账" style="width: 30%">
            <el-input v-model="form.actually"></el-input>
          </el-form-item>
          <el-form-item required label="支付内容描述" style="width: 50%">
            <el-input type="textarea" v-model="form.detail"></el-input>
          </el-form-item>
          <el-form-item required label="支付方式" style="width: 30%">
            <el-select v-model="form.payType" placeholder="请选择">
              <el-option
                v-for="item in payTypeOptions"
                :key="item.value"
                :label="item.text"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item required label="来源平台" style="width: 30%">
            <el-select v-model="form.platform" placeholder="请选择">
              <el-option
                v-for="item in platformOptions"
                :key="item.value"
                :label="item.text"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item required label="资产类型" style="width: 30%">
            <el-select v-model="form.wealthType" placeholder="请选择">
              <el-option
                v-for="item in wealthTypeOptions"
                :key="item.value"
                :label="item.text"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
import ManaApi from "@/api/index";

export default {
  name: "storeUserModify",
  data() {
    return {
      form: {
        actually: 0,
        detail: "",
        formId: 0,
        money: 0,
        payType: "",
        platform: "",
        wealthType: "money",
      },
      payTypeOptions: [],
      wealthTypeOptions: [],
      platformOptions: [],
    };
  },
  methods: {
    save() {
      let form = JSON.parse(JSON.stringify(this.form));
      form.actually = this.$bigNumber("times", form.actually, 100);
      form.money = this.$bigNumber("times", form.money, 100);

      ManaApi.chargeOrder.edit(form).then((res) => {
        if (res.code == 200) {
          this.$message.success("操作成功");
          this.$router.go(-1);
        }
      });
    },
    getInfo() {
      ManaApi.chargeOrder
        .detail({
          targetId: this.$route.query.id,
        })
        .then((res) => {
          this.form = {
            actually: this.$bigNumber("div", res.data.actually, 100),
            detail: res.data.detail,
            formId: res.data.id,
            money: this.$bigNumber("div", res.data.money, 100),
            payType: res.data.payType,
            platform: res.data.platform,
            wealthType: res.data.wealthType,
          };
        });
    },
    getConstant() {
      return new Promise((resolve, reject) => {
        ManaApi.constant
          .all({})
          .then((res) => {
            this.wealthTypeOptions = res.data.WealthType;
            this.payTypeOptions = res.data.PayType;
            this.platformOptions = res.data.Platform;
            resolve();
          })
          .catch((err) => {
            reject();
          });
      });
    },
  },
  async mounted() {
    await this.getConstant();
    if (this.$route.query.type == "edit") {
      this.getInfo();
    }
  },
};
</script>
<style lang="scss" scoped>
.storeUserModify {
}
</style>